package com.juzipi.thread.test;

import java.util.concurrent.*;

/**
 * @Author juzipi
 * @Date 2021/6/15 15:37
 * @Info
 */
public class ThreadTest2 implements Callable<Object> {


    @Override
    public Object call() throws Exception {
        for (int i = 0; i < 10; i++) {
            System.out.println(i+"你好漂亮");
        }
        return 10;
    }

    public static void main(String[] args) {
        ThreadTest2 threadTest2 = new ThreadTest2();
        ThreadTest2 threadTest21 = new ThreadTest2();
        ThreadTest2 threadTest22 = new ThreadTest2();
        ThreadTest2 threadTest23 = new ThreadTest2();
        ExecutorService executorService = Executors.newFixedThreadPool(4);
        Future<Object> submit = executorService.submit(threadTest2);
        Future<Object> submit1 = executorService.submit(threadTest21);
        Future<Object> submit2 = executorService.submit(threadTest22);
        Future<Object> submit3 = executorService.submit(threadTest23);
        try {
            Object o = submit.get();
            Object o1 = submit1.get();
            Object o2 = submit2.get();
            Object o3 = submit3.get();
            System.out.println(o);
            System.out.println(o1);
            System.out.println(o2);
            System.out.println(o3);
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        } finally {
            executorService.shutdownNow();
        }

    }


}
